package top.seekincs.controller;

import org.springframework.web.bind.annotation.*;
import top.seekincs.entity.AlumniSchoolEntity;
import top.seekincs.service.AlumniSchoolService;

import java.util.Objects;

@RestController
@RequestMapping("/school")
public class AlumniSchoolController {

    final AlumniSchoolService alumniSchoolService;

    public AlumniSchoolController(AlumniSchoolService alumniSchoolService) {
        this.alumniSchoolService = alumniSchoolService;
    }

    @PostMapping("/add")
    public AlumniSchoolEntity addSchool(String name, String description) {
        if (Objects.isNull(name) || Objects.isNull(description)) {
            return null;
        }
        return alumniSchoolService.addSchool(name, description);
    }

    @GetMapping("/name")
    public Integer getSchoolIdByName(String name) {
        Integer id = alumniSchoolService.findIdByName(name);
        return id == null ? 0 : id;
    }


    @GetMapping("/id")
    public AlumniSchoolEntity getById(@RequestParam Integer id) {
        return alumniSchoolService.findById(id);
    }
}
